//
//  IMViewCell.m
//  QuantumWar
//
//  Created by mysj on 16/7/14.
//  Copyright © 2016年 zeng. All rights reserved.
//

#import "IMViewCell.h"
#import "Message.h"
#import <Masonry.h>
#import "NSString+Add.h"
#import "UIView+Add.h"

#define Cellmg    5

#define textFont [UIFont systemFontOfSize:10.0f]
#define timeFont [UIFont systemFontOfSize:12.0f]

@interface IMViewCell ()
@property (nonatomic, strong) UILabel *timeLabel;
@property (nonatomic, strong) UILabel *label;
@end

@implementation IMViewCell

- (void)setModel:(Message *)model {
    _model = model;

    self.timeLabel.text = _model.m_time;
    
    self.label.attributedText = model.text;
    
//    [self.label sizeToFit];
//    [self layoutIfNeeded];
 
}


#pragma mark -
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        self.backgroundColor = [UIColor clearColor];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self prepareView];
    }
    return  self;
}

- (void)prepareView {
    
    [self.contentView addSubview:self.timeLabel];
    [self.contentView addSubview:self.label];
    
    [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(Cellmg);
        make.top.equalTo(self.contentView);
    }];
    
    [self.label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.timeLabel.mas_top);
        make.left.equalTo(self.timeLabel.mas_right).offset(Cellmg);
    }];
       CGFloat width = [UIScreen mainScreen].bounds.size.width - [self.timeLabel.text widthForFont:[UIFont systemFontOfSize:12]] - 10;
    self.label.preferredMaxLayoutWidth = width;
}


- (UILabel *)label {
    if (!_label) {
        _label = [[UILabel alloc] init];
        _label.font = textFont;
        _label.textColor = [UIColor colorWithHexString:@"6de8ff"];
        _label.numberOfLines = 0;
    }
    return _label;
}

- (UILabel *)timeLabel {
    if (!_timeLabel) {
        _timeLabel = [[UILabel alloc] init];
        _timeLabel.textColor = [UIColor whiteColor];
        _timeLabel.font = timeFont;
        _timeLabel.text = @"00:00";
    }
    return _timeLabel;
}
@end
